var regUtils = {};
var passwordUtils = {};
passwordUtils.passwordReg = /^[0-9]{6}$/;
//regUtils.mobileExp = /^1\d{10}$/;
regUtils.mobileExp = /^(0|86|17951)?(13[0-9]|15[0-9]|16[6]|17[0-9]|18[0-9]|19[89]|14[0-9])[0-9]{8}$|^(852|00852)?(9|6)[0-9]{7}$|^(853|00853)?(6)[0-9]{7}$|^(|886|00886)?(09)[0-9]{8}$/;
regUtils.emailExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
regUtils.damaiCodeExp = /^[1-9]\d*$/;
regUtils.moneyExp = /^[0-9]\d*([.]\d{1,2})?$/;
regUtils.numberExp = /^[0-9]\d*$/;
regUtils.dateExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;
//regUtils.realNameExp = /^([a-zA-Z]|[\u4E00-\u9FA5]|.|·|•){2,20}$/;
regUtils.realNameExp = /^([a-zA-Z\\s]|[\u4E00-\u9FA5]|[·•・·.。;*&]|[^\\x00-\\xff]){2,15}$/;
regUtils.identificationExp = /^[a-zA-Z0-9]{1,18}$/;
regUtils.imgValidateCodeExp = /^[a-zA-Z0-9]{4}$/;
regUtils.msgValidateCodeExp = /^\d{6}$/;
regUtils.bankAccountNameExp = /^([a-zA-Z]{1,12}|[\u4E00-\u9FA5]{1,6})$/;
regUtils.bankCardNoExp = /^\d{1,24}$/;
regUtils.certificateExp = /^(11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65|71|81|82|91)[0-9]{4}(17|18|19|20){1}[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])[0-9]{3}([0-9]|x|X)$/;
regUtils.certificateRASSimpleExp = /^(810|820|830)[0-9]{14}[0-9xX]$/;
//regUtils.detailAddressExp = /^([a-z]|[A-Z]|[\u4e00-\u9fa5]|[0-9]|[-－＿ _ ()（） , ，、／ /; ；＃ # &·＆·．－ - ~～ 。.])*$/;
regUtils.detailAddressExp = /^([a-z]|[A-Z]|[\u4E00-\u9FA5]|[0-9]|[\uff00-\uffff]|[-－＿ _ ()（） , ，、／ /; ；+＃ # &·＆·．－ - ~～ \。\.\：\:\n]){4,120}$/;
/**
 * 判断是否包含特殊字符
 */
regUtils.isdetailAddress = function(detailAddress) {
	if (typeof detailAddress == "undefined") {
		return false;
	}
//	if (this.numberExp.test(detailAddress)) {
//		return true;
//	}
	var b = !this.detailAddressExp.test(detailAddress);
	return b;
};

/**
 * 判断身份证，包括港澳台、大陆
 * @param certificate
 * @returns {boolean}
 */
regUtils.isCertificateFinal = function(certificate) {
	if (regUtils.isCertificateRSA(certificate)) {
		return true;
	}
	return regUtils.isCertificate(certificate);
}

/**
 * 判断身份证
 */
regUtils.isCertificate = function(certificate) {
	if (typeof certificate == "undefined") {
		return false;
	}
	if (!this.certificateExp.test(certificate)) {
		return false;
	}
	certificate = certificate.toUpperCase();
	var sum = 0, ai = 0, wi = 0;
	var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
	var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
	for (var i = 0; i < 17; i++) {
		ai = certificate.charAt(i);
		wi = factor[i];
		sum += ai * wi;
	}
	return ((parity[sum % 11]) == (certificate.charAt(17)));
};

/**
 * 判断身份证，港澳台，不验证真伪
 */
regUtils.isCertificateRSA = function(certificate) {
	if (typeof certificate == "undefined") {
		return false;
	}
	return this.certificateRASSimpleExp.test(certificate);
};

/**
 * 判断是否是手机号
 */
regUtils.isMobile = function(mobile) {
	if (typeof mobile == "undefined") {
		return false;
	}
	return this.mobileExp.test(mobile);
};
/**
 * 验证图形验证码
 */
regUtils.isImgValidateCode = function(imgCode) {
	if (typeof imgCode == "undefined") {
		return false;
	}
	return this.imgValidateCodeExp.test(imgCode);
};
/**
 * 验证短信验证码
 */
regUtils.isMsgValidateCodeExp = function(msgValidateCode) {
	if (typeof msgValidateCode == "undefined") {
		return false;
	}
	return this.msgValidateCodeExp.test(msgValidateCode);
};
/**
 * 判断是否是邮件
 */
regUtils.isEmail = function(email) {
	if (typeof email == "undefined") {
		return false;
	}
	return this.emailExp.test(email);
};
/**
 * 判断是否是大麦用户code
 */
regUtils.isDamaiCode = function(damaiCode) {
	if (typeof damaiCode == "undefined") {
		return false;
	}
	return this.damaiCodeExp.test(damaiCode);
};
regUtils.isMoney = function(money) {
	if (typeof money == "undefined") {
		return false;
	}
	return this.moneyExp.test(money);
};
regUtils.isNumber = function(number) {
	if (typeof number == "undefined") {
		return false;
	}
	return this.numberExp.test(number);
};
regUtils.isDate = function(date) {
	if (typeof date == "undefined") {
		return false;
	}
	return this.dateExp.test(date);
};
regUtils.isRealName = function(realName) {
	if (typeof realName == "undefined") {
		return false;
	}
	realName = Trim(realName, "g");
	return this.realNameExp.test(realName);
};
/**
 * 验证银行账户名称
 */
regUtils.isBankAccountName = function(bankAccountName) {
	if (typeof bankAccountName == "undefined") {
		return false;
	}
	return this.bankAccountNameExp.test(bankAccountName);
};
/**
 * 验证银行账户号码
 */
regUtils.isBankCardNo = function(bankCardNo) {
	if (typeof bankCardNo == "undefined") {
		return false;
	}
	return this.bankCardNoExp.test(bankCardNo);
};
regUtils.isIdentification = function(identification) {
	if (typeof identification == "undefined") {
		return false;
	}
	return this.identificationExp.test(identification);
};
passwordUtils.checkPassword = function(password) {
	if (typeof password == "undefined") {
		return false;
	}
	return this.passwordReg.test(password);
};
function removeIlligalChart(password) {
	password = password.replace(
			/[^0-9a-zA-z~!`@#\$%&\^\*\)\(\-\+\|_=\\,\.\/><\?;':"\}{\[\]]/, "");
	return password;
}

function Trim(str, is_global)

{
	var result;
	result = str.replace(/(^\s+)|(\s+$)/g, "");
	if (is_global.toLowerCase() == "g")
		result = result.replace(/\s/g, "");
	return result;

}

function isUserLogin() {
	var cookieStr = document.cookie;
	var index = cookieStr.indexOf("damai.cn_user");
	if (index < 0) {
		window.location.href = "https://secure.damai.cn/login.aspx?ru="
				+ window.location.href;
	}
}

// 获取当前系统日期时分秒 格式： yyyy-MM-dd HH:mm:ss
function getSystemDateNow() {
	var data = new Date();
	var year = data.getFullYear(); // 获取年
	var month = data.getMonth() + 1; // 获取月(获取当前月实际值少1 所以要加上1)
	if (parseInt(month) < 10) {
		month = "0" + month;
	}
	var day = data.getDate();
	if (parseInt(day) < 10) {
		day = "0" + day;
	}
	var hours = data.getHours();
	if (parseInt(hours) < 10) {
		hours = "0" + hours;
	}
	var minutes = data.getMinutes();
	if (parseInt(minutes) < 10) {
		minutes = "0" + minutes;
	}
	var seconds = data.getSeconds();
	if (parseInt(seconds) < 10) {
		seconds = "0" + seconds;
	}
	var time = year + "-" + month + "-" + day + " " + hours + ":" + minutes
			+ ":" + seconds;
	return time;
}

// 校验startDate是否小于endDate
function compareDate(startDate, endDate) {
	var start = new Date(startDate.replace("-", "/").replace("-", "/"));
	var end = new Date(endDate.replace("-", "/").replace("-", "/"));
	if (end < start) {
		return false;
	}
	return true;
}
// post提交
function postURL(url, params) {
	var postForm = $('<form action="' + url
			+ '" method="POST" style="display:none"></form>');
	var input;
	for ( var name in params) {
		input = $('<input type="text"/>');
		input.attr('name', $.trim(name));
		input.attr('value', $.trim(params[name]));
		postForm.append(input);
	}
	$('body').append(postForm);
	$(postForm).submit();
}

var timer = null;
function openWindow(content) {
	$('.time_mask').show();
	timer = setTimeout(function() {
		$('.time_mask').hide();
	}, 3000);
	$('.time_mask').children('p').first().text(content);
}
$(function() {
	$(document).click(function() {
		$('.time_mask').hide();
		clearTimeout(timer);
		$('.time_mask').children('p').first().text('');
	});
});

function openWindow1(content) {
	var b = $(window).height();
	var h = $('.time_mask').height();
	$('.time_mask').css({
		top : (b - h) / 2 + $(document).scrollTop() + "px"

	});
	$('.time_mask').show();
	timer = setTimeout(function() {
		$('.time_mask').hide();
	}, 3000);
	$('.time_mask').children('p').first().text(content);

}

/**
 * 页面弹出消息，模拟alert
 * 
 * @param message
 */
function popAlert(message) {
	var popDiv = '';
	popDiv += '<div class="pop-bm-sjhmcw dm-layer-box din">';
	popDiv += '<div class="dm-layer">';
	popDiv += '<div class="hd">';
	popDiv += '<h3></h3>';
	popDiv += '<a href="#" class="close" id="close"></a>';
	popDiv += '</div>';
	popDiv += '<div class="c-n">';
	popDiv += message;
	popDiv += '<div class="dm-layer-btn">';
	popDiv += '<button class="btn03 close" id="sure">确&nbsp;&nbsp;定</button>';
	popDiv += '</div>';
	popDiv += '</div>';
	popDiv += '</div>';
	popDiv += '</div>';
	$popDiv = $(popDiv);
	$("body").append($popDiv);
	popFunL($popDiv);
	var $close = $popDiv.find(".close");
	$close.click(function() {
		$popDiv.remove();
	});
};


function popFunL(ele) {
	var $ele = $(ele), $close = $ele.find(".close"), $docH = $(window).height(), $docW = $(
			document).width(), $H = $ele.height(), $W = $ele.width(), $mask = $("<div class='ljj-mask'></div>");

	$ele.show().css({
		"left" : ($docW - $W) / 2 + "px",
		"top" : ($docH - $H) / 2 + "px",
		"zIndex" : 10001
	});
	$("body").append($mask.css({
		"height" : $(document).height() + "px"
	}));
	$close.click(function() {
		$ele.hide();
		$mask.remove();
		return false;
	});
	$("button[name='aa']").click(function() {
		$ele.hide();
		$mask.remove();
		return false;
	});
	$("button[name='bb']").click(function() {
		$ele.hide();
		$mask.remove();
		window.location.reload(true);
		return false;
	});

	$(window).scroll(function() {
		// alert("s")
		$ele.css({
			"top" : ($docH - $H) / 2 + $(document).scrollTop() + "px"
		});
	});
};

function voteProgFun(pre, ele) {
	var $ele = $(ele);
	for (var i = 0; i < $ele.length; i++) {
		$ele.eq(i).animate({
			"width" : pre[i] + "%"
		}, 1000);
	}
	;
};


